package test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Test;

public class ParseTime {
	/**
	 * 日期转化为特定时间格式字符串
	 * format(new Date())方法
	 */
	@Test
	public void formatTest(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
		String time = sdf.format(new Date());
		System.out.println(time);
	}
	
	/**
	 * 日期格式字符串转换为日期类
	 * @throws ParseException
	 */
	@Test
	public void parseTest() throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String time = "2018-09-12";
		Date date = sdf.parse(time);
		System.out.println(date.toString());
	}
}
